package com.yy.job.boot.service;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yy.job.boot.constants.JobBootConstants;
import com.yy.job.boot.utils.RequestIPUtils;
import com.yy.job.facade.JobFacade;
import com.yy.job.facade.model.YYJobModel;
import com.yy.job.facade.model.YYJobStepModel;

@Service
public class Case2Service {
	
	@Autowired
	private JobFacade jobFacade;
	
	public Long createTrue(HttpServletRequest request, String ip) throws Exception {
		YYJobModel jobModel = new YYJobModel();
		jobModel.setProjectCode(JobBootConstants.PROJECT_CODE);
		jobModel.setModuleCode(JobBootConstants.MODULE1_CODE);
		jobModel.setJobCode("jobCode3");
		jobModel.setBusinessNo("bus_" + new Date().getTime());
		jobModel.setOperator(StringUtils.isNotEmpty(ip) ? ip : RequestIPUtils.getIPAddress(request));
		
		YYJobStepModel task1 = new YYJobStepModel();
		task1.setStepCode("jobTask1");
		
		YYJobStepModel task2 = new YYJobStepModel();
		task2.setStepCode("jobTask2");
		
		jobModel.addJobStep(task1);
		jobModel.addJobStep(task2);
		
		
		Long submitJob = this.jobFacade.submitJob(jobModel);
		
		return submitJob;
	}
	
	public Long createFalse(HttpServletRequest request, String ip) throws Exception {
		YYJobModel jobDTO = new YYJobModel();
		jobDTO.setProjectCode(JobBootConstants.PROJECT_CODE);
		jobDTO.setModuleCode(JobBootConstants.MODULE1_CODE);
		jobDTO.setJobCode("jobCode3");
		jobDTO.setBusinessNo("bus_" + new Date().getTime());
		jobDTO.setOperator(StringUtils.isNotEmpty(ip) ? ip : RequestIPUtils.getIPAddress(request));
		
		YYJobStepModel task1 = new YYJobStepModel();
		task1.setStepCode("jobTask1");
		task1.setStepParams("step1Param");
		
		YYJobStepModel task2 = new YYJobStepModel();
		task2.setStepCode("jobTask2");
		task2.setStepParams("step2Param");
		
		YYJobStepModel task3 = new YYJobStepModel();
		task3.setStepCode("jobTask3");
		task3.setStepParams("step3Param");
		
		YYJobStepModel task4 = new YYJobStepModel();
		task4.setStepCode("jobTask4");
		task4.setStepParams("step4Param");
		
		jobDTO.addJobStep(task1);
		jobDTO.addJobStep(task2);
		jobDTO.addJobStep(task3);
		//jobDTO.addJobStep(task4);

		Long submitJob = this.jobFacade.submitJob(jobDTO);
		
		return submitJob;
	}
	
}
